package com.jlf.core.engine.persistence.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.jlf.core.engine.dao.SchemaIndexDao;
import com.jlf.core.engine.domain.SchemaIndexDO;
import com.jlf.core.engine.persistence.SchemaIndexPersistence;
import com.jlf.core.mp.persistence.impl._SimplePersistenceImpl;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;

import java.util.Collection;
import java.util.List;

/**
 * 模型领域的索引的持久化服务
 *
 * @author wujr
 * 2023/7/14
 * @version 1.0
 * 【变更历史】
 * [wujr 2023/7/14 1.0 新增]
 */
@Slf4j
@RequiredArgsConstructor
public class SchemaIndexPersistenceImpl extends _SimplePersistenceImpl<SchemaIndexDao, SchemaIndexDO>
        implements SchemaIndexPersistence {
    @Override
    public List<SchemaIndexDO> loadByDomain(String domainCode) {
        QueryWrapper<SchemaIndexDO> wrapper = new QueryWrapper<>();
        wrapper.lambda().eq(SchemaIndexDO::getDomainCode, domainCode);
        return super.list(wrapper);
    }

    @Override
    public List<SchemaIndexDO> loadByDomains(Collection<String> domainCodes, Integer status) {
        QueryWrapper<SchemaIndexDO> wrapper = new QueryWrapper<>();
        wrapper.lambda().in(SchemaIndexDO::getDomainCode, domainCodes)
                .eq(status != null, SchemaIndexDO::getStatus, status);
        return super.list(wrapper);
    }

    @Override
    public void removeByDomain(String domainCode) {
        QueryWrapper<SchemaIndexDO> wrapper = new QueryWrapper<>();
        wrapper.lambda().eq(SchemaIndexDO::getDomainCode, domainCode);
        super.remove(wrapper);
    }
}
